package com.xbe.commandlinerunner;

import com.xbe.netty.NettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Author: liuzhiting
 * @Desctription: TODO
 * @Date: Created in 2020-08-18 18:45
 * @Version: 1.0
 */
@Component
@ConditionalOnClass(NettyServer.class)
public class NettyServerListener implements ApplicationListener<ContextRefreshedEvent>
{
    @Autowired
    private NettyServer nettyServer;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent)
    {
        new Thread(new Runnable()
        {
            @Override
            public void run()
            {

                System.out.println("8989端口启动");
                nettyServer.bind(8989);

            }
        }).start();

    }
}
